package com.example.smart_community.mapper;

import com.example.smart_community.po.*;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface RepairorderMapper {
    @Select("select * from repairorder where id=#{id}")
    @Results({
            @Result(property = "requestId",column = "request_id"),
            @Result(property = "statusId",column = "status_id"),
            @Result(property = "staffId",column = "staff_id"),
            @Result(
                    property ="maintainrequest" ,column ="request_id",
                    javaType= Maintainrequest.class,
                    one=@One(select ="com.example.smart_community.mapper.MaintainrequestMapper.selectById")
            ),
            @Result(
                    property ="staff" ,column ="staff_id",
                    javaType= Staff.class,
                    one=@One(select ="com.example.smart_community.mapper.StaffMapper.selectById")
            ),
            @Result(
                    property ="maintainstatus" ,column ="status_id",
                    javaType= Maintainstatus.class,
                    one=@One(select ="com.example.smart_community.mapper.MaintainstatusMapper.selectById")
            )

    })
    Repairorder selectById(Integer id);
    @Select("select * from  repairorder where status_id=#{statusId}")
    @Results({
            @Result(property = "requestId",column = "request_id"),
            @Result(property = "statusId",column = "status_id"),
            @Result(property = "staffId",column = "staff_id"),
            @Result(
                    property ="maintainrequest" ,column ="request_id",
                    javaType= Maintainrequest.class,
                    one=@One(select ="com.example.smart_community.mapper.MaintainrequestMapper.selectById")
            ),
            @Result(
                    property ="staff" ,column ="staff_id",
                    javaType= Staff.class,
                    one=@One(select ="com.example.smart_community.mapper.StaffMapper.selectById")
            ),
            @Result(
                    property ="maintainstatus" ,column ="status_id",
                    javaType= Maintainstatus.class,
                    one=@One(select ="com.example.smart_community.mapper.MaintainstatusMapper.selectById")
            )

    })
    List<Repairorder> selectByStatus(Integer statusId);
    @Select("select * from repairorder where staff_id=#{staffId}")
    @Results({
            @Result(property = "requestId",column = "request_id"),
            @Result(property = "statusId",column = "status_id"),
            @Result(property = "staffId",column = "staff_id"),
            @Result(
                    property ="maintainrequest" ,column ="request_id",
                    javaType= Maintainrequest.class,
                    one=@One(select ="com.example.smart_community.mapper.MaintainrequestMapper.selectById")
            ),
            @Result(
                    property ="staff" ,column ="staff_id",
                    javaType= Staff.class,
                    one=@One(select ="com.example.smart_community.mapper.StaffMapper.selectById")
            ),
            @Result(
                    property ="maintainstatus" ,column ="status_id",
                    javaType= Maintainstatus.class,
                    one=@One(select ="com.example.smart_community.mapper.MaintainstatusMapper.selectById")
            )

    })
    List<Repairorder> selectByStaffId(Integer staffId);
    @Insert("INSERT  into repairorder(request_id,status_id)values(#{requestId},#{statusId})")
    @Results({
            @Result(property = "requestId",column = "request_id"),
            @Result(property = "statusId",column = "status_id")
    })
    int insertRepairorder(Integer requestId,Integer statusId);
    @Update("update repairorder set staff_id=#{StaffId},assigntime=#{assigntime},status_id=#{statusId} where id=#{id}")
    @Results({
            @Result(property = "statusId",column = "status_id"),
            @Result(property = "staffId",column = "staff_id")
    })
    int updateAssign(@Param("id") Integer id,@Param("StaffId") Integer staffId,@Param("assigntime") String assigntime,@Param("statusId") Integer statusId);
    @Update("UPDATE repairorder set status_id=#{statusId} where id=#{id}")
    @Results({
            @Result(property = "statusId",column = "status_id"),
    })
    int updateProcessing(@Param("id") Integer id,@Param("statusId") Integer statusId);
    @Update("UPDATE repairorder set completetime=#{completetime}, status_id=#{statusId} where id=#{id}")
    @Results({
            @Result(property = "statusId",column = "status_id"),
    })
    int updateComplate(@Param("id") Integer id,@Param("completetime") String completetime,@Param("statusId") Integer statusId);
    @Update("update repairorder set staff_id=#{staffId},assigntime=#{assigntime},status_id=#{statusId} where id=#{id}")
    @Results({
            @Result(property = "staffId",column = "staff_id"),
            @Result(property = "statusId",column = "status_id")
    })
    int updateCancel(@Param("id") Integer id,@Param("staffId")Integer staffId ,@Param("assigntime") String assigntime,@Param("statusId") Integer statusId);
}
